<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML" 4.01"//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- Created: August 17, 2001-->
<!--
$Id: RepTemplate.php,v 1.2 2001/11/02 15:00:10 eugenem Exp eugenem $
$Header: /export/home/eugenem/public_html/ComplianceReports/RCS/RepTemplate.php,v 1.2 2001/11/02 15:00:10 eugenem Exp eugenem $
$Log: RepTemplate.php,v $
Revision 1.2  2001/11/02 15:00:10  eugenem
Moved database connect statements to a separate file.

This report returns a list of all machines that are overdue for a survey
-->

<html>
<head>
<title>Radiological Equipment Database</title>
<meta name="author" content="Eugene Mah">
<link rev="made" href="mailto:eugenem@ix.netcom.com">
<link rev="home" href="http://home.netcom.com/~eugenem/">
<meta name="description" content="">
<meta name="Keywords" content="">
<meta name="Reply-to" content="eugenem@ix.netcom.com">
<META http-equiv="PICS-Label" content='(PICS-1.1 "http://www.classify.org/safesurf/" l r (SS~~0001))'>
<?PHP
require('functions.inc');
require('dbc.inc');

$today = date("Ymd");
$year = date("Y");
$month = date("m");
$day = date("d");
?>
</head>

<body>
<h1>Radiological Equipment Database</h1>
<h2>Overdue surveys as of <?php echo $today; ?></h2>
<table border="0" summary="Overdue Surveys">
  <tr>
    <th>Machine</th><th>Last Survey</th>
  </tr>
<?php
/* Select machines that are active and require annual surveys */
$query = "select MachineID,Modality,Description,Location,Room from Machines " .
    "left join Modality using (ModalityID) " .
    "left join Location using (LocationID) " .
    "where Status='Active' and SurveyFreq='Annual' " .
    "order by ModalityID,MachineID";
if (!($machineRslt = mysql_query($query))) {
  echo "Unable to perform query: $query <br />\n" . mysql_error() . "<br />\n";
}
/*
 * Get the survey date for each machine if the most recent survey date
 * was more than 1 year ago
 */
while ($machine = mysql_fetch_array($machineRslt)) {
  $query = "select SID,TDate from " .
      "(select SurveyID as SID,TestDate as TDate from TestDates where MachineID=" . $machine['MachineID'] . " " .
      "order by TestDate desc limit 1) as SDates " .
      "where date_add(TDate, interval 1 year) < curdate()";
  if (!($surveyRslt = mysql_query($query))) {
    echo "Unable to perform query: $query <br />\n" . mysql_error() . "<br />\n";
  }

  if ($surveyLatest = mysql_fetch_array($surveyRslt)) {
    echo "  <tr>\n";
    printf("    <td><a href=\"SurveyAdd.php?MachID=%d\">%s</a></td>\n",$machine['MachineID'],$machine['Description']);
    printf("    <td>%s</td>\n",$surveyLatest['TDate']);
    echo "  </tr>\n";
  }
}
?>
</table>
<p><a href="index.html" target="_top" >Main menu</a></p>
</body>
</html>
